<template>
	<popupVue v-if="isShow">
		<view class="wrap-poster-popup">
			<view class="code-bg">
				<image
					class="img"
					mode="widthFix"
					@longpress="onSave"
					:src="$wanlshop.oss(codeImg)"
				/>
			</view>
			
			<view class="btn-bg flex align-center">
				<view class="btn one" @click.stop="onDismiss">
					取消
				</view>
				
				<view class="btn two">
					长按图片保存
				</view>
			</view>
		</view>
	</popupVue>
</template>

<script>
	import { getPoster } from "../../API/team.js";
	import popupVue from "../popup/popup.vue";
	export default {
		components: {
			popupVue
		},
		props: {
			/**
			 * 是否显示
			 */
			isShow: {
				type: Boolean,
				default: false,
			}
		},
		data() {
			return {
				codeImg: "",
			}
		},
		mounted() {
			this.getData(); 
		},
		methods: {
			/**
			 * 关闭
			 */
			onDismiss() {
				this.$emit("update:isShow", false);
			},
			/**
			 * 保存图片
			 */
			onSave() {
				this.$filters.onSaveImage(this.$wanlshop.oss(this.codeImg));
			},
			/**
			 * 网络请求
			 */
			getData() {
				getPoster().then(res => {
					this.codeImg = res.data;
				})
			}
		}
	}
</script>

<style lang="scss">
	.wrap-poster-popup {
		width: 600rpx;
		overflow: hidden;
		
		.code-bg {
			width: 100%;
			box-sizing: border-box;
			overflow: hidden;
			
			.img {
				width: 100%;
				height: auto;
			}
		}
		
		.btn-bg {
			margin-top: 80rpx;
			width: 100%;
			overflow: hidden;
			gap: 20rpx;
			
			.btn {
				flex: 1;
				height: 82rpx;
				line-height: 82rpx;
				text-align: center;
				overflow: hidden;
				border-radius: 50rpx;
				font-size: 30rpx;
			}
			.one {
				background-color: white;
				color: #333333;
			}
			
			.two {
				color: white;
				background: linear-gradient(to right, #84BD00, #4982EA);
			}
		}
	}
</style>